package lambda;

import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * @Author 12629
 * @Date 2022/4/4 20:19
 * @Description：
 */
//无返回值无参数
@FunctionalInterface
interface NoParameterNoReturn {
    void test();
}
//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}
//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}

//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}

//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}
//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}



public class Test1 {

    public static void main4(String[] args) {
        NoParameterReturn noParameterReturn = ()->{return 10;};

        NoParameterReturn noParameterReturn2 = ()-> 10;

        int ret = noParameterReturn2.test();
        System.out.println(ret);

        OneParameterReturn oneParameterReturn = (a)->a;
        ret = oneParameterReturn.test(48);
        System.out.println(ret);

        MoreParameterReturn moreParameterReturn=(a,b)->a+b;
        ret = moreParameterReturn.test(1,2);
        System.out.println(ret);

    }

    public static void main3(String[] args) {

        int size = 10;
        NoParameterNoReturn noParameterNoReturn = ()->{
            //size = 100;
            System.out.println("haha"+ size);
        };
        noParameterNoReturn.test();
        //
        OneParameterNoReturn oneParameterNoReturn = a -> System.out.println(a);


        OneParameterNoReturn oneParameterNoReturn2 = (a) -> {
            System.out.println(a);
        };


        oneParameterNoReturn.test(10);

        MoreParameterNoReturn moreParameterNoReturn = (a,b)->{
            System.out.println(a+b);
        };

        //如果方法体 只有一条语句的时候
        MoreParameterNoReturn moreParameterNoReturn2 = (a,b)->System.out.println(a+b);

        moreParameterNoReturn.test(1,2);

    }



    public static void main1(String[] args) {
        MoreParameterReturn moreParameterReturn = new MoreParameterReturn(){
            @Override
            public int test(int a, int b) {
                return a+b;
            }
        };

        MoreParameterReturn moreParameterReturn2 = (int a,int b)->{return a+b;};


        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1-o2;
            }
        });

        PriorityQueue<Integer> priorityQueue1 = new PriorityQueue<>((o1, o2) -> {return o1-o2;});

    }
}
